package org.rency.ues.engine.validator;

import org.rency.ues.common.UesValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractRequestValidator<Request,Response> implements RequestValidator<Request,Response> {
	
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	public Response validator(Request request) {
		logger.debug("{}请求参数校验开始. [{}]", this.getValidatorName(), request);
		try{
			UesValidator.validator(request);
			this.validate(request);
			return this.success();
		}catch (IllegalArgumentException e) {
			logger.error("{}请求校验失败.", this.getValidatorName(), e);
			return this.fail(e.getMessage());
		}
	}

	protected abstract void validate(Request request);
	
	protected abstract String getValidatorName();

    protected abstract Response success();

    protected abstract Response fail(String returnMessage);

}
